package top.luckyluxcis.api;

import lombok.experimental.UtilityClass;
import top.luckyluxcis.RollApi;
import top.luckyluxcis.consts.AreaType;
import top.luckyluxcis.type.Area;
import top.luckyluxcis.util.MapUtil;

import java.util.List;
import java.util.Map;

/**
 * 全国/世界城市信息，数据来源国家统计局
 *
 * @author Zhuang
 * @since 2023/9/21
 */
@SuppressWarnings("unused")
@UtilityClass
public class AreaUtil {
    private static final RollApi API = RollApi.getInstance();

    /**
     * 获取全国城市列表信息
     *
     * @return {@link List}<{@link Area}>
     */
    public static List<Area> list() {
        return API.get("/address/list", MapUtil.empty(), List.class, Area.class);
    }

    /**
     * 搜索全国城市列表信息
     *
     * @param code  类型 0-查询省份 1-查询城市
     * @param value 被查询的省份或者城市名称
     * @return {@link List}<{@link Area}>
     */
    public static List<Area> search(AreaType code, String value) {
        Map<String, Object> params = MapUtil.<String, Object>builder()
                .put("code", code)
                .put("value", value)
                .build();
        return API.get("/address/list", params, List.class, Area.class);
    }

    /**
     * 获取世界级国家城市列表
     *
     * @return {@link List}<{@link Area}>
     */
    public static List<Area> worldCityList() {
        return API.get("/address/v2/list", MapUtil.empty(), List.class, Area.class);
    }

    /**
     * 获取全国城市信息-省份列表
     *
     * @return {@link List}<{@link Area}>
     */
    public static List<Area> listProvince() {
        return API.get("/address/v3/list/province", MapUtil.empty(), List.class, Area.class);
    }

    /**
     * 获取全国城市信息-城市列表
     *
     * @param provinceCode 省份编码
     * @return {@link List}<{@link Area}>
     */
    public static List<Area> listCity(String provinceCode) {
        Map<String, Object> params = MapUtil.<String, Object>builder()
                .put("provinceCode", provinceCode)
                .build();
        return API.get("/address/v3/list/city", params, List.class, Area.class);
    }

    /**
     * 获取全国城市信息-区列表
     *
     * @param provinceCode 省份编码
     * @param cityCode     市编码
     * @return {@link List}<{@link Area}>
     */
    public static List<Area> listDistrict(String provinceCode, String cityCode) {
        Map<String, Object> params = MapUtil.<String, Object>builder()
                .put("provinceCode", provinceCode)
                .put("cityCode", cityCode)
                .build();
        return API.get("/address/v3/list/area", params, List.class, Area.class);
    }

    /**
     * 获取全国城市信息-街道列表
     *
     * @param provinceCode 省份编码
     * @param cityCode     市编码
     * @param areaCode     区编码
     * @return {@link List}<{@link Area}>
     */
    public static List<Area> listStreet(String provinceCode, String cityCode, String areaCode) {
        Map<String, Object> params = MapUtil.<String, Object>builder()
                .put("provinceCode", provinceCode)
                .put("cityCode", cityCode)
                .put("areaCode", areaCode)
                .build();
        return API.get("/address/v3/list/street", params, List.class, Area.class);
    }

    /**
     * 列表村
     * 获取全国城市信息-村委会列表
     *
     * @param provinceCode 省份编码
     * @param cityCode     市编码
     * @param areaCode     区编码
     * @param streetCode   街道编码
     * @return {@link List}<{@link Area}>
     */
    public static List<Area> listVillage(String provinceCode, String cityCode, String areaCode, String streetCode) {
        Map<String, Object> params = MapUtil.<String, Object>builder()
                .put("provinceCode", provinceCode)
                .put("cityCode", cityCode)
                .put("areaCode", areaCode)
                .put("streetCode", streetCode)
                .build();
        return API.get("/address/v3/list/village", params, List.class, Area.class);
    }
}
